package com.zzsoft.task;/**
 * Created by zhanghb on 2019/9/7.
 */

import com.zzsoft.util.SocketUtil;
import io.netty.channel.Channel;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description
 * @Author Zhanghb
 * @Date
 */
@Component
public class Scheduler{
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    //每隔2秒执行一次
    @Scheduled(fixedRate = 5000)
    public void testTasks() {
        System.out.println("定时任务执行时间：" + dateFormat.format(new Date()));
        /*Channel channel = SocketUtil.get("key001");
        if(channel!=null) {
            channel.writeAndFlush("ok");
        }*/
    }

    //每天3：05执行
    @Scheduled(cron = "0 05 03 ? * *")
    public void testTasks1() {
        System.out.println("定时任务执行时间：" + dateFormat.format(new Date()));
    }


}
